package com.gin.no_gay_alliance.activity;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuInflater;
import android.widget.RadioGroup;

import androidx.appcompat.widget.Toolbar;

import com.gin.no_gay_alliance.R;
import com.gin.no_gay_alliance.adpter.history.ObservedTopicAdapter;
import com.gin.no_gay_alliance.database.entity.ReplyHistoryTopic;
import com.gin.no_gay_alliance.database.manager.ReplyHistoryManager;
import com.gin.no_gay_alliance.databinding.ActivityReplyHistoryConfigBinding;
import com.gin.no_gay_alliance.utils.AlertDialogUtils;

import java.util.List;

/**
 * 回复历史配置
 *
 * @author : ginstone
 * @version : v1.0.0
 * @since : 2023/9/16 17:11
 **/
public class ReplyHistoryConfigActivity extends BaseBindingActivity<ActivityReplyHistoryConfigBinding> implements RadioGroup.OnCheckedChangeListener {

    private ObservedTopicAdapter adapter;

    /**
     * 解析意图
     *
     * @param intent 意图
     */
    @Override
    protected void handleIntent(Intent intent) {

    }

    /**
     * onCreate中的后续操作
     */
    @Override
    protected void onCreate() {
        //初始值
        switch (ReplyHistoryManager.getMode()) {
            case NORMAL:
                b.radioGroup.check(R.id.rb_mode_normal);
                break;
            case HISTORY:
                b.radioGroup.check(R.id.rb_mode_history);
                break;
            case CLOSED:
                b.radioGroup.check(R.id.rb_mode_closed);
                break;
        }
        b.radioGroup.setOnCheckedChangeListener(this);

        adapter = new ObservedTopicAdapter(this);
        b.recyclerView.setAdapter(adapter);

        List<ReplyHistoryTopic> list = ReplyHistoryManager.listObservedTopic();
        adapter.updateData(list);
    }

    /**
     * 装载右上角菜单
     *
     * @param menu         菜单
     * @param menuInflater 菜单渲染器
     */
    @Override
    protected void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {

    }

    @Override
    protected Toolbar initToolbar() {
        return b.toolbar;
    }

    @SuppressLint("NotifyDataSetChanged")
    @Override
    protected void onResume() {
        super.onResume();
        adapter.notifyDataSetChanged();
    }

    /**
     * RadioGroup 切换选项的回调
     */
    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        if (checkedId == R.id.rb_mode_normal) {
            ReplyHistoryManager.setMode(ReplyHistoryManager.Mode.NORMAL);
            AlertDialogUtils.showMessage(this, "常规模式", "本模式下, 只有观察列表中的主题中的回复内容会被记录", null);
        }
        if (checkedId == R.id.rb_mode_history) {
            ReplyHistoryManager.setMode(ReplyHistoryManager.Mode.HISTORY);
            AlertDialogUtils.showMessage(this, "历史模式", "本模式下, 所有你看到过的回复均会被记录", null);
        }
        if (checkedId == R.id.rb_mode_closed) {
            ReplyHistoryManager.setMode(ReplyHistoryManager.Mode.CLOSED);
            AlertDialogUtils.showMessage(this, "关闭", "本模式下, 不会记录任何的回复内容", null);
        }
    }

    public static void startActivity(Context context) {
        context.startActivity(new Intent(context, ReplyHistoryConfigActivity.class));
    }
}
